import json
from typing import List

from colorama import Fore

from effect.util.console.SuperConsole import print_dict_as_column_table
from effect.util.data.clear import split_dict


def inner(slave_infos_str):
    if slave_infos_str == {}:
        print("什么都没有")
        return
    data = split_dict(slave_infos_str, 10)
    for i in data:
        print_dict_as_column_table(i, 34)


def dicts2table(_dict: List[dict]):
    print(">>>", _dict)
    allinfo = []
    for i in _dict:
        slave_infos_str = {}

        try:
            for name, value in i.items():
                if value is None:
                    value = "空"
                value = str(value)
                if value.isnumeric():
                    int_value = int(value)
                    if int_value >= 80:
                        value = Fore.GREEN + value + Fore.WHITE
                        name = Fore.GREEN + name + Fore.WHITE
                    elif 80 > int_value >= 60:
                        value = Fore.CYAN + value + Fore.WHITE
                        name = Fore.CYAN + name + Fore.WHITE
                    elif 60 > int_value > 50:
                        value = value
                    else:
                        value = Fore.RED + value + Fore.WHITE
                        name = Fore.RED + name + Fore.WHITE

                slave_infos_str[name] = [value]
        except ValueError:
            pass
        allinfo.append(lambda _slave_infos_str=slave_infos_str: inner(json.loads(json.dumps(_slave_infos_str))))

    return allinfo
